import { defineStore } from 'pinia';
import {ref, reactive, computed} from 'vue'

interface AnyType {
    [props:string]:any
}

export const testStore = defineStore('test', ()=>{

    let todos:AnyType = ref([{id:1,title:"吃饭1"},{id:2,title:"吃饭2"},{id:3,title:"吃饭3"}])
    let arr = ref([1,2,3,4,5])
    const total = computed(()=>{
        return arr.value.reduce((pre:any,cur:any)=>{
            return pre+cur
        },0)
    })

    const updateData=()=>{
        todos.value.push({id:Math.random(),title:"吃饭"})
    }

    return {
        todos,
        arr,
        total,
        updateData
    }
});
